import React, { Component } from 'react';
import css from './index.less';
import FilterSearch from '@/components/FilterSearch';
import TableList from '@/components/TableList';
import EditModal from '@/components/EditModal';
import { Button, Divider } from 'antd';
import { connect } from 'dva';
import { timeFormat } from '@/utils/common';
import { Link } from 'react-router-dom';
import Status from '@/pages/components/Status';
import AuthButton from '@/components/AuthButton';

type State = {
  selectProject: any;
};
type Props = {
  dispatch: Function;
};
class Department extends Component<Props> {
  state: State = {
    selectProject: {},
  };
  table = null;

  filters = [
    {
      key: 'serviceTypeUuid',
      type: 'select',
      label: '项目类型',
      asyncopt: {
        url: '/api/data/v1/getDataList',
        data: {
          code: 'service',
        },
      },
    },
    {
      key: 'budget',
      type: 'select',
      label: '投资概算',
      options: this.props.dict.budget,
    },
    {
      key: 'approveStatus',
      type: 'select',
      label: '评审状态',
      options: this.props.dict.approveStatus,
    },
    {
      key: 'year',
      type: 'select',
      label: '选择年份',
      options: this.props.dict.searchYear,
    },
    {
      key: 'name',
      type: 'input',
      label: '项目名称',
    },
  ];
  columns = [
    {
      title: '报送日期',
      dataIndex: ['project', 'createTime'],
      width: 150,
      render: text => timeFormat(text, 'YYYY-MM-DD'),
    },
    {
      title: '项目名称',
      dataIndex: ['project', 'name'],
      render: (text, data) => (
        <Button onClick={() => this.goDetail(data, true)} type="link">
          {text}
        </Button>
      ),
    },
    {
      title: '项目ID',
      dataIndex: ['project', 'no'],
      width: 180,
    },
    { title: '项目类型', dataIndex: ['project', 'serviceTypeData', 'display'] },
    { title: '投资概算（万元）', dataIndex: 'budget' },
    {
      title: '评审增减金额（万元）',
      dataIndex: ['examineRecordVO', 'changeAmount'],
    },
    {
      title: '审批状态',
      dataIndex: 'examineRecordVO',
      render: (text, data) =>
        text ? '已评审' : <span style={{ color: '#327CEC' }}>待评审</span>,
    },
  ];
  goDetail = ({ uuid }, readOnly) => {
    const url = `projectFillIn/scheme/edit?id=${uuid ||
      ''}&type=1&readOnly=${readOnly || ''}`;
    this.props.dispatch({
      type: '$router/forward',
      payload: {
        url,
      },
    });
  };
  render() {
    const { selectProject } = this.state;
    return (
      <div>
        <FilterSearch
          filters={this.filters}
          onSearch={val => this.table.fetch(val)}
        >
          <AuthButton type="primary" role="add_report">
            <Link to={{ pathname: '/projectFillIn/scheme/edit' }}>添加</Link>
          </AuthButton>
        </FilterSearch>
        <TableList
          post
          rowKey="id"
          onRef={c => {
            this.table = c;
          }}
          columns={this.columns}
          source="/api/scheme/v1/query"
        />
      </div>
    );
  }
}

export default connect(state => state.base)(Department);
